package com.ncloud.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.system.entity.UserRole;

@Mapper
public interface UserRoleMapper {

	@Insert("insert into sys_user_role(user_id,role_id,eff_date,exp_date)"
			+ " values(#{userId}, #{roleId}, #{effDate}, #{expDate})")
	void createUserRole(UserRole userRole);
	
	@Update("update sys_user_role set exp_date = now() where user_id = #{userId} and role_id=#{roleId}"
			+ " and now() between eff_date and exp_date")
	void deleteUserRole(UserRole userRole);

	@Select("select cast(role_id as char) as roleId from sys_user_role where user_id = #{userId} and now() between eff_date and exp_date")
	List<String> getRolesbyUserId(Long userId);

}
